package com.ruoyi.web.controller.jypc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jypc.domain.Canteenorder;
import com.ruoyi.jypc.service.ICanteenorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用餐订单Controller
 * 
 * @author wwq
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/jypc/canteenorder")
public class CanteenorderController extends BaseController
{
    @Autowired
    private ICanteenorderService canteenorderService;

    /**
     * 查询用餐订单列表
     */
    @PreAuthorize("@ss.hasPermi('jypc:canteenorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Canteenorder canteenorder)
    {
        startPage();
        List<Canteenorder> list = canteenorderService.selectCanteenorderList(canteenorder);
        return getDataTable(list);
    }

    /**
     * 导出用餐订单列表
     */
    @PreAuthorize("@ss.hasPermi('jypc:canteenorder:export')")
    @Log(title = "用餐订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Canteenorder canteenorder)
    {
        List<Canteenorder> list = canteenorderService.selectCanteenorderList(canteenorder);
        ExcelUtil<Canteenorder> util = new ExcelUtil<Canteenorder>(Canteenorder.class);
        util.exportExcel(response, list, "用餐订单数据");
    }

    /**
     * 获取用餐订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('jypc:canteenorder:query')")
    @GetMapping(value = "/{orderid}")
    public AjaxResult getInfo(@PathVariable("orderid") Long orderid)
    {
        return AjaxResult.success(canteenorderService.selectCanteenorderByOrderid(orderid));
    }

    /**
     * 新增用餐订单
     */
    @PreAuthorize("@ss.hasPermi('jypc:canteenorder:add')")
    @Log(title = "用餐订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Canteenorder canteenorder)
    {
    	canteenorder.setCreateBy(getUsername());
        return toAjax(canteenorderService.insertCanteenorder(canteenorder));
    }

    /**
     * 修改用餐订单
     */
    @PreAuthorize("@ss.hasPermi('jypc:canteenorder:edit')")
    @Log(title = "用餐订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Canteenorder canteenorder)
    {
    	canteenorder.setUpdateBy(getUsername());
        return toAjax(canteenorderService.updateCanteenorder(canteenorder));
    }

    /**
     * 删除用餐订单
     */
    @PreAuthorize("@ss.hasPermi('jypc:canteenorder:remove')")
    @Log(title = "用餐订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderids}")
    public AjaxResult remove(@PathVariable Long[] orderids)
    {
        return toAjax(canteenorderService.deleteCanteenorderByOrderids(orderids));
    }
}
